﻿@page "/operationLog"
@inherits AdminCompontentBase

<PageTitle>
    @T("OperationLog")
</PageTitle>
<div style="height: calc(100vh - 250px);@(_operationLogs.Count<=2?"min-height: calc(100vh - 120px);":"")">
    <AutoHeight AutoClass="mt-6 m-sheet theme--light m-card pa-6 full-height pr-0">
        <HeaderContent>
            <div class="d-flex">
                <SDateTimeRangeToolbar StartDateTime=_startTime EndDateTime=_endTime OnUpdate="OnDateTimeUpdate" Clearable></SDateTimeRangeToolbar>
                <MSpacer />
                <EnumAutoComplete @bind-Value="OperationType" I18NScope="@PageName" TValue="OperationTypes" Label="@T("OperationType")" Clearable FillBackground=false Class="ml-6" Style="width: 100px !important;" />
                <SUserAutoComplete @bind-Value="UserId" Label="@T("Operator")" FillBackground=false Class="ml-6" Clearable Style="width: 134px !important;" />
                <SSearch @bind-Value="Search" BackgroundColor="#fff" Placeholder="@T("Please enter operation description")" Class="ml-6" Style="width: 134px !important;" />
            </div>
        </HeaderContent>
        <AutoHeightContent>
            <MVirtualScroll OverscanCount=5 TItem="OperationLogDto" Items="_operationLogs" Class="rounded-0">
                <ItemContent>
                    <div class="d-flex mb-6" style="height:36px;">
                        <div class="mr-1 h5 regular--text">@context.OperationTime.ToString("MM-dd")</div>
                        <div class="body regular3--text">@context.OperationTime.ToString("HH:mm:ss")</div>
                    </div>
                    <div>
                        @{
                            var logItems = new List<(string, string)>
                            {
                                (T(nameof(OperationLogDto.Operator)), context.OperatorName),
                                (T(nameof(OperationLogDto.OperationType)), T(context.OperationType.ToString())),
                                (T(nameof(OperationLogDto.OperationDescription)), context.OperationDescription)
                            };
                            
                            // 添加客户端信息，如果存在的话
                            if (!string.IsNullOrEmpty(context.ClientId))
                            {
                                logItems.Add((T("ClientId"), context.ClientId));
                            }
                        }
                        
                        @foreach (var (key, value) in logItems)
                        {
                            <div class="d-flex mb-6">
                                <div class="mr-3" style="color: #7681AB;">
                                    @key
                                </div>
                                <MDivider Vertical></MDivider>
                                <div class="ml-3" style="color: #323D6F;">
                                    @value
                                </div>
                            </div>
                        }
                    </div>
                    <MDivider Class="mb-6" />
                </ItemContent>
            </MVirtualScroll>
        </AutoHeightContent>
        <FooterContent>
            <SPagination Class="mt-6" @bind-Page="Page" @bind-PageSize=PageSize Total=_total />
        </FooterContent>
    </AutoHeight>
</div>
